package demoa.yls.example.com.myapplication;

import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button btnSend;
    private MyBroadcastReceiver receiver;
    private HighReceiver hReceiver;
    private MidReceiver mReceiver;
    private LowReceiver lReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        IntentFilter hfilter=new IntentFilter();
        hfilter.addAction("weather-report");
        hfilter.setPriority(100);
        hReceiver=new HighReceiver();
        registerReceiver(hReceiver,hfilter);

        IntentFilter mfilter=new IntentFilter();
        mfilter.addAction("weather-report");
        mfilter.setPriority(100);
        mReceiver=new MidReceiver();
        registerReceiver(mReceiver,mfilter);

        IntentFilter lfilter=new IntentFilter();
        lfilter.addAction("weather-report");
        lfilter.setPriority(100);
        lReceiver=new LowReceiver();
        registerReceiver(lReceiver,lfilter);

        btnSend=findViewById(R.id.btn_send);
        btnSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent=new Intent();
                intent.setAction("weather-report");
                sendOrderedBroadcast(intent,null);

            }
        });



    }
}

